<template>
	<view class="" style="min-height: 100vh;">
		<view class="m-flex" v-for="(item,index) in baotuis" :key="index" @click="toGoodsInfo(item.id)"
			style="margin-bottom: 60rpx;">
			<view class="m-col-l">
				<view class="goods-thumb-view" style="margin-right: 30rpx;">
					<u-image width="100%" height="250rpx" border-radius="10" :src="item.mainPic">
						<u-loading slot="loading"></u-loading>
					</u-image>
				</view>
			</view>
			<view class="m-col-r" style="position: relative;">
				<view class="u-line-2">
					<u-tag style="margin-right: 8rpx;" text="淘宝" mode="dark" type="error" size="mini"
						shape="square" :closeable="false" />
					<text>{{item.title}}</text>
				</view>
				<view class="" style="position: absolute;bottom: 0;width: 100%;">
					<view class="u-flex u-row-between">
						<view class="u-font-40" style="color: #ff0010;margin-bottom: 10rpx;font-weight: 600;">
							<text>￥{{item.actualPrice}}</text>
							<text class="del-price">￥{{item.originalPrice}}</text>
						</view>
						<view class="coupon">
							<text>{{item.couponPrice}}元券</text>
						</view>
					</view>
					<view class="u-line-1">
						<u-icon name="taobao-circle-fill" size="32" color="#ff0100"></u-icon>{{item.shopName}}
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default{
		props:['cid'],
		data(){
			return{
				page: 1,
				baotuis: [],
			}
		},
		created() {
			console.log('cid：'+this.cid)
			if(this.cid > 0){
				this.getCategoryGoods(this.cid,1)
			}else{
				this.getBaoTui();
			}
		},
		methods:{
			toGoodsInfo(id) {
				uni.navigateTo({
					url: '../show/show?id=' + id
				})
			},
			getBaoTui() {
				let baotuis = this.myCache('baotuis');
				if (!baotuis) {
					this.$myRequest('/baoTui', {
						pageSize: 20,
					}).then(res => {
						this.baotuis = res.data.list
						this.myCache('baotuis', this.baotuis, 60)
					})
				} else {
					console.log('使用缓存数据！')
					this.baotuis = baotuis
				}
			},
			loadingMore() {
				if(this.cid !=0){
					this.getCategoryGoods(this.cid,this.page)
				}else{
					uni.showLoading({
						title: '加载中'
					})
					this.$myRequest('/baoTui', {
						pageSize: 20,
						page: ++this.page
					}).then(res => {
						try {
							this.baotuis = this.baotuis.concat(res.data.list)
						} catch (e) {
							uni.showToast({
								title: '没有新数据啦！',
								icon: 'none'
							})
							console.log('就这么多数据了。')
						}
						uni.hideLoading();
					})
				}
			},
			getCategoryGoods(cid,page){
				uni.showLoading({
					title: '数据加载中'
				})
				this.$myRequest('/goodsList',{cids:cid,page:page,pageSize:20}).then(res=>{
					console.log('我最终加载的数据cid为'+cid+'页码为'+page)
					this.page++
					if(page > 1){
						this.baotuis = this.baotuis.concat(res.data.list)
					}else{
						this.baotuis=res.data.list
					}
					uni.hideLoading();
				}).catch(err=>{
					console.log(err)
					uni.hideLoading();
				})
			}
		}
	}
</script>

<style>
	
</style>
